package com.ruoyi.report_chl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_chl.domain.bo.ReportChlHxzsBsInfoBo;
import com.ruoyi.report_chl.domain.vo.ReportChlHxzsBsInfoVo;
import com.ruoyi.report_chl.domain.ReportChlHxzsBsInfo;
import com.ruoyi.report_chl.mapper.ReportChlHxzsBsInfoMapper;
import com.ruoyi.report_chl.service.IReportChlHxzsBsInfoService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 粉煤灰活性指数试验检测记录Service业务层处理
 *
 * @author zyb
 * @date 2024-10-31
 */
@RequiredArgsConstructor
@Service
@Transactional
public class ReportChlHxzsBsInfoServiceImpl implements IReportChlHxzsBsInfoService {

    private final ReportChlHxzsBsInfoMapper baseMapper;

    /**
     * 查询粉煤灰活性指数试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportChlHxzsBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询粉煤灰活性指数试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportChlHxzsBsInfoVo> queryPageList(ReportChlHxzsBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportChlHxzsBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportChlHxzsBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询粉煤灰活性指数试验检测记录列表
     */
    @Override
    public List<ReportChlHxzsBsInfoVo> queryList(ReportChlHxzsBsInfoBo bo) {
        LambdaQueryWrapper<ReportChlHxzsBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportChlHxzsBsInfo> buildQueryWrapper(ReportChlHxzsBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportChlHxzsBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportChlHxzsBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportChlHxzsBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportChlHxzsBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportChlHxzsBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportChlHxzsBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportChlHxzsBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportChlHxzsBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportChlHxzsBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportChlHxzsBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportChlHxzsBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsj()), ReportChlHxzsBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportChlHxzsBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportChlHxzsBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportChlHxzsBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportChlHxzsBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportChlHxzsBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportChlHxzsBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportChlHxzsBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportChlHxzsBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportChlHxzsBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportChlHxzsBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(bo.getJiancjg() != null, ReportChlHxzsBsInfo::getJiancjg, bo.getJiancjg());
        lqw.eq(bo.getA1() != null, ReportChlHxzsBsInfo::getA1, bo.getA1());
        lqw.eq(bo.getB1() != null, ReportChlHxzsBsInfo::getB1, bo.getB1());
        lqw.eq(bo.getC1() != null, ReportChlHxzsBsInfo::getC1, bo.getC1());
        lqw.eq(bo.getD1() != null, ReportChlHxzsBsInfo::getD1, bo.getD1());
        lqw.eq(bo.getE1() != null, ReportChlHxzsBsInfo::getE1, bo.getE1());
        lqw.eq(bo.getF1() != null, ReportChlHxzsBsInfo::getF1, bo.getF1());
        lqw.eq(bo.getG1() != null, ReportChlHxzsBsInfo::getG1, bo.getG1());
        lqw.eq(bo.getH1() != null, ReportChlHxzsBsInfo::getH1, bo.getH1());
        lqw.eq(bo.getI1a() != null, ReportChlHxzsBsInfo::getI1a, bo.getI1a());
        lqw.eq(bo.getI1b() != null, ReportChlHxzsBsInfo::getI1b, bo.getI1b());
        lqw.eq(bo.getI1c() != null, ReportChlHxzsBsInfo::getI1c, bo.getI1c());
        lqw.eq(bo.getJ1a() != null, ReportChlHxzsBsInfo::getJ1a, bo.getJ1a());
        lqw.eq(bo.getJ1b() != null, ReportChlHxzsBsInfo::getJ1b, bo.getJ1b());
        lqw.eq(bo.getJ1c() != null, ReportChlHxzsBsInfo::getJ1c, bo.getJ1c());
        lqw.eq(bo.getK1a() != null, ReportChlHxzsBsInfo::getK1a, bo.getK1a());
        lqw.eq(bo.getK1b() != null, ReportChlHxzsBsInfo::getK1b, bo.getK1b());
        lqw.eq(bo.getK1c() != null, ReportChlHxzsBsInfo::getK1c, bo.getK1c());
        lqw.eq(bo.getL1a() != null, ReportChlHxzsBsInfo::getL1a, bo.getL1a());
        lqw.eq(bo.getL1b() != null, ReportChlHxzsBsInfo::getL1b, bo.getL1b());
        lqw.eq(bo.getL1c() != null, ReportChlHxzsBsInfo::getL1c, bo.getL1c());
        lqw.eq(bo.getM1() != null, ReportChlHxzsBsInfo::getM1, bo.getM1());
        lqw.eq(bo.getN1() != null, ReportChlHxzsBsInfo::getN1, bo.getN1());
        lqw.eq(bo.getA2() != null, ReportChlHxzsBsInfo::getA2, bo.getA2());
        lqw.eq(bo.getB2() != null, ReportChlHxzsBsInfo::getB2, bo.getB2());
        lqw.eq(bo.getC2() != null, ReportChlHxzsBsInfo::getC2, bo.getC2());
        lqw.eq(bo.getD2() != null, ReportChlHxzsBsInfo::getD2, bo.getD2());
        lqw.eq(bo.getE2() != null, ReportChlHxzsBsInfo::getE2, bo.getE2());
        lqw.eq(bo.getG2() != null, ReportChlHxzsBsInfo::getG2, bo.getG2());
        lqw.eq(bo.getH2() != null, ReportChlHxzsBsInfo::getH2, bo.getH2());
        lqw.eq(bo.getI2a() != null, ReportChlHxzsBsInfo::getI2a, bo.getI2a());
        lqw.eq(bo.getI2b() != null, ReportChlHxzsBsInfo::getI2b, bo.getI2b());
        lqw.eq(bo.getI2c() != null, ReportChlHxzsBsInfo::getI2c, bo.getI2c());
        lqw.eq(bo.getJ2a() != null, ReportChlHxzsBsInfo::getJ2a, bo.getJ2a());
        lqw.eq(bo.getJ2b() != null, ReportChlHxzsBsInfo::getJ2b, bo.getJ2b());
        lqw.eq(bo.getJ2c() != null, ReportChlHxzsBsInfo::getJ2c, bo.getJ2c());
        lqw.eq(bo.getK2a() != null, ReportChlHxzsBsInfo::getK2a, bo.getK2a());
        lqw.eq(bo.getK2b() != null, ReportChlHxzsBsInfo::getK2b, bo.getK2b());
        lqw.eq(bo.getK2c() != null, ReportChlHxzsBsInfo::getK2c, bo.getK2c());
        lqw.eq(bo.getL2a() != null, ReportChlHxzsBsInfo::getL2a, bo.getL2a());
        lqw.eq(bo.getL2b() != null, ReportChlHxzsBsInfo::getL2b, bo.getL2b());
        lqw.eq(bo.getL2c() != null, ReportChlHxzsBsInfo::getL2c, bo.getL2c());
        lqw.eq(bo.getM2() != null, ReportChlHxzsBsInfo::getM2, bo.getM2());
        lqw.eq(bo.getA3() != null, ReportChlHxzsBsInfo::getA3, bo.getA3());
        lqw.eq(bo.getB3() != null, ReportChlHxzsBsInfo::getB3, bo.getB3());
        lqw.eq(bo.getC3() != null, ReportChlHxzsBsInfo::getC3, bo.getC3());
        lqw.eq(bo.getD3() != null, ReportChlHxzsBsInfo::getD3, bo.getD3());
        lqw.eq(bo.getE3() != null, ReportChlHxzsBsInfo::getE3, bo.getE3());
        lqw.eq(bo.getF3() != null, ReportChlHxzsBsInfo::getF3, bo.getF3());
        lqw.eq(bo.getG3() != null, ReportChlHxzsBsInfo::getG3, bo.getG3());
        lqw.eq(bo.getH3() != null, ReportChlHxzsBsInfo::getH3, bo.getH3());
        lqw.eq(bo.getI3a() != null, ReportChlHxzsBsInfo::getI3a, bo.getI3a());
        lqw.eq(bo.getI3b() != null, ReportChlHxzsBsInfo::getI3b, bo.getI3b());
        lqw.eq(bo.getI3c() != null, ReportChlHxzsBsInfo::getI3c, bo.getI3c());
        lqw.eq(bo.getJ3a() != null, ReportChlHxzsBsInfo::getJ3a, bo.getJ3a());
        lqw.eq(bo.getJ3b() != null, ReportChlHxzsBsInfo::getJ3b, bo.getJ3b());
        lqw.eq(bo.getJ3c() != null, ReportChlHxzsBsInfo::getJ3c, bo.getJ3c());
        lqw.eq(bo.getK3a() != null, ReportChlHxzsBsInfo::getK3a, bo.getK3a());
        lqw.eq(bo.getK3b() != null, ReportChlHxzsBsInfo::getK3b, bo.getK3b());
        lqw.eq(bo.getK3c() != null, ReportChlHxzsBsInfo::getK3c, bo.getK3c());
        lqw.eq(bo.getL3a() != null, ReportChlHxzsBsInfo::getL3a, bo.getL3a());
        lqw.eq(bo.getL3b() != null, ReportChlHxzsBsInfo::getL3b, bo.getL3b());
        lqw.eq(bo.getL3c() != null, ReportChlHxzsBsInfo::getL3c, bo.getL3c());
        lqw.eq(bo.getM3() != null, ReportChlHxzsBsInfo::getM3, bo.getM3());
        lqw.eq(bo.getN3() != null, ReportChlHxzsBsInfo::getN3, bo.getN3());
        lqw.eq(bo.getA4() != null, ReportChlHxzsBsInfo::getA4, bo.getA4());
        lqw.eq(bo.getB4() != null, ReportChlHxzsBsInfo::getB4, bo.getB4());
        lqw.eq(bo.getC4() != null, ReportChlHxzsBsInfo::getC4, bo.getC4());
        lqw.eq(bo.getD4() != null, ReportChlHxzsBsInfo::getD4, bo.getD4());
        lqw.eq(bo.getE4() != null, ReportChlHxzsBsInfo::getE4, bo.getE4());
        lqw.eq(bo.getG4() != null, ReportChlHxzsBsInfo::getG4, bo.getG4());
        lqw.eq(bo.getH4() != null, ReportChlHxzsBsInfo::getH4, bo.getH4());
        lqw.eq(bo.getI4a() != null, ReportChlHxzsBsInfo::getI4a, bo.getI4a());
        lqw.eq(bo.getI4b() != null, ReportChlHxzsBsInfo::getI4b, bo.getI4b());
        lqw.eq(bo.getI4c() != null, ReportChlHxzsBsInfo::getI4c, bo.getI4c());
        lqw.eq(bo.getJ4a() != null, ReportChlHxzsBsInfo::getJ4a, bo.getJ4a());
        lqw.eq(bo.getJ4b() != null, ReportChlHxzsBsInfo::getJ4b, bo.getJ4b());
        lqw.eq(bo.getJ4c() != null, ReportChlHxzsBsInfo::getJ4c, bo.getJ4c());
        lqw.eq(bo.getK4a() != null, ReportChlHxzsBsInfo::getK4a, bo.getK4a());
        lqw.eq(bo.getK4b() != null, ReportChlHxzsBsInfo::getK4b, bo.getK4b());
        lqw.eq(bo.getK4c() != null, ReportChlHxzsBsInfo::getK4c, bo.getK4c());
        lqw.eq(bo.getL4a() != null, ReportChlHxzsBsInfo::getL4a, bo.getL4a());
        lqw.eq(bo.getL4b() != null, ReportChlHxzsBsInfo::getL4b, bo.getL4b());
        lqw.eq(bo.getL4c() != null, ReportChlHxzsBsInfo::getL4c, bo.getL4c());
        lqw.eq(bo.getM4() != null, ReportChlHxzsBsInfo::getM4, bo.getM4());
        return lqw;
    }

    /**
     * 新增粉煤灰活性指数试验检测记录
     */
    @Override
    public Boolean insertByBo(ReportChlHxzsBsInfoBo bo) {
        ReportChlHxzsBsInfo add = BeanUtil.toBean(bo, ReportChlHxzsBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改粉煤灰活性指数试验检测记录
     */
    @Override
    public Boolean updateByBo(ReportChlHxzsBsInfoBo bo) {
        ReportChlHxzsBsInfo update = BeanUtil.toBean(bo, ReportChlHxzsBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportChlHxzsBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除粉煤灰活性指数试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
